package predatorpreytest.macro.builder;

import util.PredatorPreyScenarioBuilder;
import PredatorPrey.Grass;
import PredatorPrey.Sheep;

public class SheepDieOutScenarioBuilder extends PredatorPreyScenarioBuilder {

	@SuppressWarnings({ "unchecked" })
	@Override
	protected void createAgents() {
		// create 10 grass agent..
		for (int i = 1; i <= 10; i++) {
			Grass grass = getAliveGrass("grass" + i, i, 2 * i);
			// add to the test context...
			getContext().add(grass);
		}
		// create 100 Sheep agent.
		for (int i = 1; i <= 100; i++) {
			// create Sheep agent
			Sheep sheep = this.getEnvironment().createSheep("sheep" + i);
			// add to the test context...
			getContext().add(sheep);
		}

	}

	/**
	 * Creates a new {@code Grass} agent which is always alive and acts ,n the
	 * environment with given agent name.
	 * 
	 * @param agentName
	 *            name of the agent.
	 * @param x
	 *            x coordinate of the agent.
	 * @param y
	 *            y coordinate of the agent.
	 * @return agent instance.
	 */
	private Grass getAliveGrass(String agentName, int x, int y) {
		Grass grass = this.getEnvironment().createGrass(agentName,
				this.getContext(), x, y);
		while (!grass.isAlive()) {
			grass = this.getEnvironment().createGrass(agentName,
					this.getContext(), x, y);
			if (grass.isAlive()) {
				break;
			}
		}
		return grass;
	}

}
